<html lang="en">
<head>
<meta charset="utf-8">
<meta
	content="随时随地发现新鲜事！微博带你欣赏世界上每一个精彩瞬间，了解每一个幕后故事。分享你想表达的，让全世界都能听到你的心声！"
	name="description">
<title>微博注册</title>
<link rel="stylesheet" type="text/css" href="css/weibo.css">
<script type="text/javascript" src="js/jquery-1.12.3.min.js"></script>
<script type="text/javascript">
		 function mymy(){
		 $.ajax({
				type:'get',
				url:'zhuce', 
				contentType:'application/json;charset=UTF-8',
				dataType:'text',
				success:function (result){
					
					alert(result);
				},
				error:function (){
					alert("出错");
				}
			})			  
			
			
		}
		 
	</script>
<style type="text/css">
.tip {
	width: 200px;
}
td{
	height:30px;
}
</style>
</head>
<body class="frame_login">
	<h1>注册</h1>
	<div id="contetn">
		<form action="insertuser" method="post" enctype="multipart/form-data" id="form">

			<table style="margin: auto;">
				<tr>
					<td>账号:</td>
					<td><input id="account" type="text" name="account"
						reg="^\d{8,10}$" tip="请输入8-10数字字符" state="0"></td>
					<td class="tip"></td>

				</tr>
				<tr>
					<td>密码:</td>
					<td><input id="password" type="password" name="password"
						reg="^[a-zA-Z0-9]{8,15}$" tip="8-15位字母或数字" state="0">
					</td>
					<td class="tip"></td>
				</tr>
				<tr>
					<td>用户名:</td>
					<td><input id="username" type="text" name="username"
						reg="^[\u4E00-\u9FA5A-Za-z0-9]{5,20}$" tip="5-20位字母或数字或汉字" state="0"
						></td>
					<td class="tip"></td>
				</tr>
				<tr>
					<td>
						<input type="submit" value="注册">
					</td>
					<td></td>
				</tr>
			</table>
		</form>

	</div>
	<script type="text/javascript">
		$(function (){
			//向后台发送账号进行验证重复
			function repeat(obj){
				$.ajax({
					url:'isrepetition?account='+obj.val(),
					type:'get',
					async:'false',
					dataType:'text',
					success:function (result){
						var tipobj =obj.parent().next();
						if(result == "yes" ){
							tipobj.html("<span style='color:red;'>该账号已经被注册</span>");
							obj.attr("state","0");
						}else{
							tipobj.html("");
							obj.attr("state","1");
						}
					},
					error:function (){
						alert("系统出错");
					}
				});
			}
			
			//判断账号是否重复
			 $("#account").blur(function (){
				 var yanchong = regular($("#account"));
				 if(yanchong){
					 repeat($("#account"));
				 }
			}); 
			
			//正则表达式验证
			function regular(obj){
				var obj = $(obj);
				
				var reg = new RegExp(obj.attr("reg"));
				var tip = obj.attr("tip");
				var val = obj.val();
				var tipobj = obj.parent().next();
				
				//判断正则表达式
				var is = reg.test(val);
				if(!is){
					tipobj.html("<span style='color:red;'>"+tip+"</span>");
					obj.attr("state","0");
					return false;
				}else{
					tipobj.html("");
					obj.attr("state","1");
					return true;
				}
			}
			
			$("#password").blur(function (){
				return regular($("#password"));
			});
			$("#username").blur(function (){
				return regular($("#username"));
			});
			
			//表单提交验证
			$("#form").submit(function (){
				
				//判断状态码
				var accountstate = $("#account").attr("state");
				var passwordstate = $("#password").attr("state");
				var usernamestate = $("#username").attr("state");
				if(!(accountstate==1 && passwordstate==1 &&usernamestate==1 )){
					return false;
				}else{
					return true;
				}
			});
		})
	</script>
</body>
</html>